import {getPrediction} from '@/services/luzha';

const Luzha = {
  namespace: 'luzha',
  state: {
    predictionData:{
      main:[],
      recommend:[]
    }
  },
  effects: {
    *getPrediction({ payload }, { call, put }) {
      // 请求mock接口
      const response = yield call(getPrediction, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "predictionData",
      });
    }
  },
  reducers: {
    //同步方法
    saveValues(state, { payload, name }) {
      const v = { ...state };
      v[name] = payload;
      return v;
    },
  },
  //触发器。setup表示初始化即调用。
  //正常使用的话,初始化的数据加载应该在组件挂载的时候执行
  // 其他用法见官方文档。https://github.com/sorrycc/blog/issues/62
  // subscriptions: {
  //   setup({dispatch}) {
  //     dispatch({type: 'listFetch'})
  //   }
  // }
};
export default Luzha;
